package com.example.controller;

import com.example.FlowContext;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import jakarta.annotation.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class OrderController {

    @Resource
    private FlowExecutor flowExecutor;

    @GetMapping("/case1")
    public ResponseEntity case1() {

        FlowContext flowContext = new FlowContext();
        flowContext.setProductId("1");
        flowContext.setDevice("desktop");

        LiteflowResponse response = flowExecutor.execute2Resp("getProductInfo", null, flowContext);

        HashMap<String, Object> result = new HashMap<>();
        result.put("brand", flowContext.getBrand());
        result.put("product", flowContext.getProduct());

        return new ResponseEntity(result, HttpStatus.OK);
    }

    @GetMapping("/case2")
    public ResponseEntity case2() {

        FlowContext flowContext = new FlowContext();
        flowContext.setProductId("2");
        flowContext.setDevice("mobile");

        LiteflowResponse response = flowExecutor.execute2Resp("getProductInfo", null, flowContext);

        HashMap<String, Object> result = new HashMap<>();
        result.put("brand", flowContext.getBrand());
        result.put("product", flowContext.getProduct());

        return new ResponseEntity(result, HttpStatus.OK);
    }

}
